/*
 * Grass.cpp
 *
 *  Created on: 25.10.2012
 *      Author: Martin
 */

#ifdef _WIN32 
#include <windows.h> 
#endif

#include "Grass.h"

Grass::Grass(glm::vec3 _Pos, float _r, std::string _Name,
		std::string _modelFName, ModelPool *_mPool, PathFinder *_pathfinder) :
		Vegetation(_Pos, _r, _Name, _modelFName, _mPool, _pathfinder)
{
	type = OBJ_GRASS;
	parentType = OBJ_VEGETATION;

	// override default shader id

	shaderID = Shader::sPool->getProgramID("grass");
	shadowShaderID = Shader::sPool->getProgramID("grass_sh");

}

Grass::~Grass()
{
}

void Grass::control(float t)
{
	// exit when unit is sleeping
	if (sleeping)
		return;

	facingToPoint(Camera::CamPos);
}

void Grass::facingToPoint(glm::vec3 point)
{
	float c = point.x - Pos.x;
	float b = point.z - Pos.z;
	float rRad;

	if (point.z < Pos.z)
	{
		rRad = atan(c / b) + PI;
		r = (rRad * 180.0 / PI);
	}
	else
	{
		rRad = atan(c / b);
		r = rRad * 180.0 / PI;
	}
}

